<?php

namespace App\Domain\Customer\Dao;

use App\Domain\Customer\Models\CustomerModel;
use Illuminate\Database\Eloquent\Builder;
use App\Http\Models\Permission\PermissionModel;


class CustomerDao
{
    public static function findByPhone($phone)
    {
        return CustomerModel::where('phone', $phone)->where('status', 1)->first();
    }

    public static function findByName($name)
    {
        return CustomerModel::where('name', $name)->where('status', 1)->first();
    }

    public static function findById($id)
    {
        return CustomerModel::where('id', $id)->where('status', 1)->first();
    }


    /**
     * 创建账号
     * @param $params
     * @return CustomerModel
     */
    public function create($params)
    {
        $params = array_filter_null($params);
        return CustomerModel::create($params);
    }

    /**
     * 修改账号
     * @param CustomerModel $model
     * @param $params
     * @return CustomerModel
     */
    public function update(CustomerModel $model, $params)
    {
        $params = array_filter_null($params);
        $model->fill($params)->save();
        return $model;
    }
}
